package com.farmneighbor.javaevent;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Random;

public class DataGenerator {
    public static void main(String[] args) {
        String filePath = "data.txt";
        int numRecords = 10000;

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
            // 写入表头
            writer.write("event_time,order_id,product_id,category_id,category_code,brand,price,user_id,age,sex,local\n");

            Random random = new Random();
            String[] brands = {"samsung", "huawei", "apple", "lg", "polaris", "karcher", "maestro", "philips", "asus", "epson"};
            String[] categories = {"electronics.tablet", "electronics.audio.headphone", "furniture.kitchen.table",
                    "electronics.smartphone", "appliances.kitchen.refrigerators", "appliances.personal.scales",
                    "electronics.video.tv", "computers.components.cpu", "computers.notebook",
                    "computers.peripherals.monitor", "computers.peripherals.printer"};
            String[] locations = {"广东", "江苏", "浙江", "山东", "福建", "江西", "湖南", "湖北", "河南", "河北", "山西", "陕西", "四川", "北京", "天津", "重庆"};
            String[] sexes = {"男", "女"};

            for (int i = 0; i < numRecords; i++) {
                // 生成event_time
                LocalDateTime dateTime = LocalDateTime.of(2020, 4, 1, 0, 0, 0).plusDays(random.nextInt(30));
                String eventTime = dateTime.toInstant(ZoneOffset.UTC).toString();

                // 生成order_id
                long orderId = 2290000000000000000L + random.nextInt(1000000000);

                // 生成product_id
                long productId = 1510000000000000000L + random.nextInt(1000000000);

                // 生成category_id
                double categoryId = 2.268e+18 + random.nextDouble() * 1e10;

                // 生成category_code
                String categoryCode = categories[random.nextInt(categories.length)];

                // 生成brand
                String brand = brands[random.nextInt(brands.length)];

                // 生成price
                double price = 10 + random.nextDouble() * 1000;

                // 生成user_id
                double userId = 1.515e+18 + random.nextDouble() * 1e10;

                // 生成age
                int age = 18 + random.nextInt(60);

                // 生成sex
                String sex = sexes[random.nextInt(sexes.length)];

                // 生成local
                String local = locations[random.nextInt(locations.length)];

                writer.write(eventTime + "," + orderId + "," + productId + "," + categoryId + "," + categoryCode + "," + brand + "," + price + "," + userId + "," + age + "," + sex + "," + local + "\n");
            }

            System.out.println("数据生成完成并保存到 " + filePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}